import sys

from PyQt5.QtGui import QStandardItemModel, QStandardItem, QColor
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QMainWindow, QApplication, QTableWidgetItem, QFileDialog, QMessageBox
from qtpy import QtWidgets, QtCore
from uitools import read_excel


class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        loadUi("./ui/wq.ui", self)
        self.commandLinkButton.clicked.connect(self.pen)
        self.commandLinkButton_5.clicked.connect(self.submit)
        self.commandLinkButton_7.clicked.connect(self.rubber)
        self.excel_data = read_excel()
        self.gen_table()
        self.status="pen"
    def pen(self):
        self.status="pen"
    def rubber(self):
        self.status="rubber"
    def submit(self):
        pass

    def gen_table(self):
        """设置table表头"""
        self.tableWidget.clear()
        self.tableWidget.setColumnCount(7)
        self.tableWidget.setRowCount(58)
        # 表格展示
        self.tableWidget.setHorizontalHeaderLabels(["项目", "设备ID", "仓库", "通道", "url", "编码","单位"])
        self.tableWidget.horizontalHeader().setStretchLastSection(True)
        self.tableWidget.verticalHeader().setVisible(True)
        self.tableWidget.clicked.connect(self.row_clicked)

        for row, i in enumerate(self.excel_data):
            for col, v in enumerate(i):
                item = QTableWidgetItem(v)
                self.tableWidget.setItem(row, col, item)

    def row_clicked(self, clickedIndex):
        row = clickedIndex.row()
        print(self.excel_data[row])


app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
